<?php
add_action('admin_menu', 'addAllNotificationPages');

function addAllNotificationPages() {
    add_action('admin_enqueue_scripts', 'safely_add_stylesheet_to_admin');

    function safely_add_stylesheet_to_admin() {
        wp_enqueue_style('prefix-style', get_template_directory_uri() . '/wp-admin/css/tham.css');
    }

    //add menu, page
    add_menu_page('Notification Center', 'Notification Center', 'manage_options', 'notification-center', 'notificationCenter', '', 6);
    //add page, put null to parent-slug if you don't to show it on admin menu
    add_submenu_page(null, '', '', 'manage_options', 'request-detail', 'detailQuote');
}

/**
 * show latest quotes of Requesting a quote, deal, flight, group travel
 */
function notificationCenter() {
    $aQuotes = RequestAQoute::getLatestQuote(RequestAQoute::REQUEST_A_QUOTE);
    $aFlights = RequestAQoute::getLatestQuote(RequestAQoute::REQUEST_A_FLIGHT);
    $aDeals = RequestAQoute::getLatestQuote(RequestAQoute::REQUEST_A_DEAL);
    ?>


   
    <div class='wrap'>
        <h1>Notification center</h1>        	
          <hr/>
        <?php /* --------------REQUEST A QUOTE ----------------------- */ ?>	
        <h2>Request a quote</h2>
        <table border="1" cellpadding="2" class="class_table1 class_table2">
            <tr>
                <th>Name</th>
                <th>Email</th>
                <th>Phone</th>
                <th>Leaving From</th>
                <th>Going To</th>
                <th></th>
            </tr>
            <?php
            foreach ($aQuotes as $quote) {
                $startLocation = unserialize($quote->start_location);
                $endLocation = unserialize($quote->end_location);
                ?>
                <tr>
                    <td><?php echo $quote->full_name; ?></td>
                    <td><?php echo $quote->email; ?></td>
                    <td><?php echo $quote->phone; ?></td>
                    <td>
                        <?php
                        foreach ($startLocation as $location) {
                            echo $location;
                            break;
                        }
                        ?>
                    </td>
                    <td>
                        <?php
                        foreach ($endLocation as $location) {
                            echo $location;
                            break;
                        }
                        ?>
                    </td>
                    <td><a href="?page=request-detail&i=<?php echo $quote->id_request_a_quote ?>&type=<?php echo RequestAQoute::REQUEST_A_QUOTE; ?>">View Detail</a></td>
                </tr>	    
            <?php } ?>
        </table>

        <?php /* --------------REQUEST A FLIGHT ----------------------- */ ?>	
        <br/>
         <hr/>
        <h2>Request a Flight</h2>
        <table border="1" cellpadding="2" class="class_table1 class_table2">
            <tr>
                <th>Name</th>
                <th>Email</th>
                <th>Phone</th>
                <th>Leaving From</th>
                <th>Going To</th>
                <th></th>
            </tr>
            <?php
            foreach ($aFlights as $flight) {
                $startLocation = unserialize($flight->start_location);
                $endLocation = unserialize($flight->end_location);
                ?>
                <tr>
                    <td><?php echo $flight->full_name; ?></td>
                    <td><?php echo $flight->email; ?></td>
                    <td><?php echo $flight->phone; ?></td>
                    <td>
                        <?php
                        foreach ($startLocation as $location) {
                            echo $location;
                            break;
                        }
                        ?>
                    </td>
                    <td>
                        <?php
                        foreach ($endLocation as $location) {
                            echo $location;
                            break;
                        }
                        ?>
                    </td>
                    <td><a href="?page=request-detail&i=<?php echo $flight->id_request_a_quote ?>&type=<?php echo RequestAQoute::REQUEST_A_FLIGHT; ?>">View Detail</a></td>
                </tr>	    
            <?php } ?>
        </table>

        <?php /* --------------REQUEST A DEAL ----------------------- */ ?>
        <br/>
         <hr/>
        <h2>Request a Deal</h2>
        <table border="1" cellpadding="2" class="class_table1 class_table2">
            <tr>
                <th>Name</th>
                <th>Email</th>
                <th>Phone</th>
                <th>Leaving From</th>
                <th>Going To</th>
                <th></th>
            </tr>
            <?php
            foreach ($aDeals as $deal) {
                $startLocation = unserialize($deal->start_location);
                $endLocation = unserialize($deal->end_location);
                ?>
                <tr>
                    <td><?php echo $deal->full_name; ?></td>
                    <td><?php echo $deal->email; ?></td>
                    <td><?php echo $deal->phone; ?></td>
                    <td>
                        <?php
                        foreach ($startLocation as $location) {
                            echo $location;
                            break;
                        }
                        ?>
                    </td>
                    <td>
                        <?php
                        foreach ($endLocation as $location) {
                            echo $location;
                            break;
                        }
                        ?>
                    </td>
                    <td><a href="?page=request-detail&i=<?php echo $deal->id_request_a_quote ?>&type=<?php echo RequestAQoute::REQUEST_A_DEAL; ?>">View Detail</a></td>
                </tr>	    
            <?php } ?>
        </table>
        <?php
        /*
         * 
         * Group Tour 
         */
        ?>
        <br/>
         <hr/>
        <h2>Request group tour travel</h2>
        <table border="1" cellpadding="2" class="class_table1 class_table2">
            <tr>
                <th>Group name</th>
                <th>Member Group</th>
                <th>Leaving from</th>
                <th>Going to</th>
                <th></th>
            </tr>
            <?php
            $GroupTravels = ContactForm::ListContactForm(0, 10);
            foreach ($GroupTravels as $groupTravel) {

                $submitTime = $groupTravel->submit_time;
                $listinfo = ContactForm::getInfoByIdSubmitTime($submitTime);
                ?>
                <tr>
                    <th><?php echo $listinfo['group-name']; ?></th>
                    <th><?php echo $listinfo['member-group']; ?></th>
                    <th><?php echo $listinfo['leaving-group']; ?></th>
                    <th><?php echo $listinfo['going-to']; ?></th>
                    <th><a href="?page=request-detail&i=<?php echo $submitTime; ?>&type=<?php echo RequestAQoute::GROUP_TRAVEL; ?>" > View Detail</a></th>
                </tr>
                <?php
            }
            ?>
        </table>

    </div>
    <?php
}

/**
 * show detail of request page
 */
function detailQuote() {
    //echo $_GET['i'];
    if (isset($_GET['i']) && isset($_GET['type'])) {
        /// echo $_GET['i'];
        $idRequest = $_REQUEST['i'];
        $TypeReQuest = $_REQUEST['type'];
        /*
         * Case Detail of Request A Quote , Requset A Deal and Request A Flight 
         */
        if (($TypeReQuest == RequestAQoute::REQUEST_A_QUOTE) || ($TypeReQuest == RequestAQoute::REQUEST_A_DEAL) || ($TypeReQuest == RequestAQoute::REQUEST_A_FLIGHT)) {
            ?>
            <div><h1>
                    <?php
                    if ($TypeReQuest == RequestAQoute::REQUEST_A_QUOTE) {
                        echo 'Request a quote ';
                    } else if ($TypeReQuest == RequestAQoute:: REQUEST_A_FLIGHT) {
                        echo 'Request a Flight';
                    } else if ($TypeReQuest == RequestAQoute::REQUEST_A_DEAL) {
                        echo 'Request a Deal ';
                    }
                    $listInfo = RequestAQoute::listRequestAqouteByIdRequestAquote($idRequest);


                    $listStartLocation = unserialize($listInfo[0]->start_location);
                    $listEndLocation = unserialize($listInfo[0]->end_location);
                    $listStartTime = unserialize($listInfo[0]->start_time);
                    $listEndTime = unserialize($listInfo[0]->end_time);
                    ?>
                </h1></div>
            <div>
                <table class="class_table1">
                    <tr>
                        <td class="class_tr1"> Name </td>
                        <td><?php echo $listInfo[0]->full_name; ?></td>
                    </tr>
                    <tr>
                        <td class="class_tr1"> Email </td>
                        <td><?php echo $listInfo[0]->email; ?></td>
                    </tr>
                    <tr>
                        <td class="class_tr1">  Phone number </td>
                        <td><?php echo $listInfo[0]->phone; ?></td>
                    </tr>
                    <tr>

                        <td colspan="2">
                            <?php
                            for ($i = 0; $i < count($listStartLocation); $i++) {
                                ?>
                                <div class="div-leaving">Leaving from  : <?php echo $listStartLocation[$i]; ?> </div> 
                                <div class="div-leaving" >Going to    :  <?php echo $listEndLocation[$i]; ?></div>
                                <div class="div-leaving" >Departure date - Return date   :  <?php echo $listStartTime[$i] . ' - ' . $listEndTime[$i]; ?> </div>
                                <hr>

                                <?php
                            }
                            ?>




                        </td>

                    </tr>
                    <tr>
                        <td class="class_tr1">  Adult(12+)   </td>
                        <td><?php echo $listInfo[0]->adult; ?></td>
                    </tr>
                    <tr>
                        <td class="class_tr1"> Children(2-12) </td>
                        <td><?php echo $listInfo[0]->children; ?></td>
                    </tr>
                    <tr>
                        <td class="class_tr1"> Infant(0-2) </td>
                        <td><?php echo $listInfo[0]->infant; ?></td>
                    </tr>
                    <tr>
                        <td class="class_tr1"> Class </td>
                        <td><?php
                            if ($listInfo[0]->class == DealFlight::ECONOMY) {
                                echo 'Economy';
                            } else if ($listInfo[0]->class == DealFlight::BUSINESS) {
                                echo 'Business';
                            } else if ($listInfo[0]->class == DealFlight::FIRST_CLASS) {
                                echo 'First Class ';
                            } else if ($listInfo[0]->class == DealFlight::PREMIUM_ECONOMY) {
                                echo 'Premium Economy ';
                            }
                            ?></td>
                    </tr>
                    <tr>
                        <td class="class_tr1">  Country  </td>
                        <td><?php
                            echo $listInfo[0]->city;
                            ?></td>
                    </tr>
                    <?php
                    if ($TypeReQuest <> RequestAQoute::REQUEST_A_QUOTE) {
                        ?>
                        <tr>
                            <td class="class_tr1">  Price  </td>
                            <td><?php
                                echo number_format($listInfo[0]->price);
                                ?></td>
                        </tr>
                        <?php
                    }
                    ?>

                </table>
            </div>
            <?php
        }
        /*
         * Case Group Travel
         */
        else{
              $InfoGroupTravel = ContactForm::getInfoByIdSubmitTime($idRequest);
            ?>
                <div><h1>Request group tour travel</h1></div>
                 <table class="class_table1">
                    <tr>
                        <td class="class_tr1"> Group name </td>
                        <td><?php echo $InfoGroupTravel['group-name']; ?></td>
                    </tr>
                    <tr>
                        <td class="class_tr1"> Member Group </td>
                        <td><?php echo $InfoGroupTravel['member-group']; ?></td>
                    </tr>
                    <tr>
                        <td class="class_tr1"> Leaving from </td>
                        <td><?php echo $InfoGroupTravel['leaving-group']; ?></td>
                    </tr>
                    <tr>
                        <td class="class_tr1">
                            	Going to
                        </td>
                         <td><?php echo $InfoGroupTravel['going-to']; ?></td>
                    </tr>
                    <tr>
                        <td class="class_tr1">
                            	Adult
                        </td>
                         <td><?php echo $InfoGroupTravel['adult']; ?></td>
                    </tr>
                     <tr>
                        <td class="class_tr1">
                            	Children(2-12)
                        </td>
                         <td><?php echo $InfoGroupTravel['numCHD']; ?></td>
                    </tr>
                     <tr>
                        <td class="class_tr1">
                            	Infant(0-2)
                        </td>
                         <td><?php echo $InfoGroupTravel['infant']; ?></td>
                    </tr>
                     <tr>
                        <td class="class_tr1">
                            	Class
                        </td>
                         <td><?php 
                             echo $InfoGroupTravel['class']; 
                            
                         ?></td>
                    </tr>
                    
                    
                    
                    
                   	
                 </table>
           <?php
            
        }
    } else {
        redirectTo404Page();
    }
}
